<template>
	<view class="">
		<view class="row-box" v-if="type==='flex'">
			<view class="tab-item fcc" v-for="(item,i) in list" :key="i" :class="{'tab-item-ac':i==activeIndex}"
				@click="changePagesTab(i)">
				<text class="title fc-3">{{item.title}}</text>
				<text class="link"></text>
			</view>
		</view>
		<view class="row-box inline-flexbox" v-if="type==='inline-flexbox'">
			<view class="fcc" v-for="(item,i) in list" :key="i" :class="{'tab-item-ac':i==activeIndex}"
				@click="changePagesTab(i)">
				<text class="title fc-3">{{item.title}}</text>
				<text class="link"></text>
			</view>
		</view>
		<view class="row-box gird" v-if="type==='gird'">
		</view>
		<view class="scroll">
			<u-tabs v-if="type==='scroll'" :list="list" lineColor="#00A191" keyName='title' @click="changePagesTab2"
				class="u-tabs"></u-tabs>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				activeIndex: 0
			};
		},
		created() {
			this.activeIndex = this.index
		},
		methods: {
			changePagesTab(i) {
				this.activeIndex = i
				this.$emit('change', i)
			},
			changePagesTab2(e) {
				this.activeIndex = e.index
				this.$emit('change', e.index)
			}
		},
		watch: {
			index: {
				handler(newVal, oldVal) {
					this.activeIndex = newVal
				},
			}
		},
		props: {
			type: {
				type: String,
				default: 'flex'
			},
			list: {
				type: Array,
				default: () => []
			},
			index: {
				type: Number | String,
				default: 0
			}
		},

		computed: {}
	}
</script>

<style lang="scss" scoped>
	.row-box {
		height: 100%;

		.tab-item {
			height: 100%;
			flex: 1;
			position: relative;

			.link {
				opacity: 0;
				width: 32rpx;
				height: 6rpx;
				background-color: #00A191;
				position: absolute;
				left: 50%;
				bottom: 16rpx;
				transform: translateX(-50%);
				border-radius: 50rpx;
			}
		}

		.tab-item-ac {
			position: relative;

			.title {
				color: #00A191;
			}

			.link {
				opacity: 1;
			}
		}


	}

	.inline-flexbox {
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.u-tabs {
		overflow: hidden;
	}
</style>